import axios, {AxiosRequestConfig} from "axios";
import Nprogress from 'nprogress';
import {message} from "antd";

axios.defaults.timeout = 10000;
axios.defaults.headers.post["Content-Type"] = "application/json;charset=utf-8";

Nprogress.configure({showSpinner: false})

axios.interceptors.request.use(config => {
  // 设置header token
  // const token = localStorage.getItem("userInfo");
  // token && (config.headers.common["Authorization"] = `Bearer ${token}`);
  Nprogress.start()
  return config;
})

axios.interceptors.response.use(config => {
  Nprogress.done()
  return config?.data;
}, err => {
  Nprogress.done()
  if (err.response?.data) {
    message.error(`${err.response?.data?.message}`);
  }
  return null;
})

export default (config: AxiosRequestConfig) => {
  return axios(config)
}
